<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table cellspacing="0" border="0" width="995">
	<tr>
		<td width="995" class="title_manager_product">Quản lý download</td>
	</tr>
	<tr>
		<td height="90">
			<table border="0" cellpadding="0" cellspacing="0" width="995">
				<tr>
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><img src="images/CreateNews.gif" width="48" height="47" border="0" /></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=downloadAdmin&do=formadddownloadcategory">Tạo danh mục download</a></td>
							</tr>
						</table>
						
					</td>
					
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><img src="images/CreateCategory.gif" width="51" height="48" border="0" /></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=downloadAdmin&do=formaddfile">Thêm tài liệu download</a></td>
							</tr>
						</table>
						
					</td>
					
				</tr>
			</table>
		</td>	
	</tr>
</table>

<table class="reference" cellspacing="0" border="0" width="995">
	<tr>
		<td width="795">
			<form action="index.php?admin=downloadAdmin&do=formaddfile" method="post" enctype="multipart/form-data">
				<table cellspacing="0" border="0" width="795">
					<tr>
						<td width="795" class="title_manager_product">Thêm tài liệu</td>
					</tr>
				</table>
				<table class="reference" cellspacing="0" border="1" width="100%">
					<tr><td height="20" colspan="2"></td></tr>
					<tr>
						<td colspan="2" align="center">
							<?php
								$filename = $_POST['filename'];
								$cateID = $_POST['cateID'];
								$download = 0;
								
								$target="../download/";
								$link=$target.$_FILES['fileUp']['name'];
								move_uploaded_file($_FILES['fileUp']['tmp_name'],$link);
	
								if(isset($_POST['submit'])){
									if($filename==''){
										echo "<font color=\"red\">Bạn phải nhập vào tên tài liệu.</font>";
									}else{
										$query="INSERT INTO productdownloads (cateID,filename,filelink,download,datecreated) VALUES ('$cateID','$filename','$link','$download','')";
								mysql_query($query) or die(mysql_error());
								echo "Thêm tài liệu thành công";
								echo "<script>window.location='index.php?admin=downloadAdmin&do=listdownload'</script>";
									}
								}
							?>
						</td>
					</tr>
					<tr>
						<td align="right"><b>Tên tài liệu:</b></td>
						<td><input type="text" name="filename" size="30" /></td>
					</tr>
					<tr>
						<td align="right"><b>Danh mục:</b></td>
						<td>
							<select name="cateID">
								<option value="">Chọn danh mục</option>
								<?php
									$id=$_GET['id'];
									$query="select * from productdownloadcategories";
									$result=mysql_query($query);
									while($row=mysql_fetch_array($result)){?>
									<option value="<?php echo $row['id'];?>"><?php echo $row['titleDownload'];?></option>
								<?php
								}
								?>
							</select>
						</td>	
					</tr>
					<tr>
						<td align="right"><b>Upload tài liệu:</b></td>
						<td><input type="file" name="fileUp" size="30" /></td>
					</tr>
					<tr>
						<td></td>
						<td>
							<input type="submit" name="submit" value="Thêm tài liệu" />
							<input type="button" name="Cancel" value="Cancel" onclick="window.location = 'index.php?admin=downloadAdmin&do=listdownload' " />
						</td>
					</tr>
				</table>
			</form>
		</td>
	</tr>	
</table>
</body>
</html>